package com.example.blogback.common;

import lombok.Data;


/**
 * 统一结果封装
 */
@Data
public class Result {
    private String code;
    private String msg;
    private Object data;

    public static Result success(Object data){
        Result result = new Result();
        result.setCode("0");
        result.setData(data);
        result.setMsg("请求成功");
        return result;
    }

    public static Result success(String msg,Object data){
        Result result = new Result();
        result.setCode("0");
        result.setData(data);
        result.setMsg(msg);
        return result;
    }

    public static Result fail(String msg){
        Result result = new Result();
        result.setCode("-1");
        result.setMsg(msg);
        return result;
    }

    public static Result fail(String msg,Object data){
        Result result = new Result();
        result.setCode("-1");
        result.setData(data);
        result.setMsg(msg);
        return result;
    }

    public static Result fail(String code, String message, Object o) {

        Result result = new Result();
        result.setCode(code);
        result.setData(o);
        result.setMsg(message);
        return result;

    }
}
